// webpack.config.js
const path = require('path')
const InjectScriptsPlugin = require('./InjectScriptsPlugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
  entry: './src/index.ts',
  mode: 'development',
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: 'ts-loader',
        include: [path.resolve(__dirname, 'src')]
      },
      {
        test: /\.html$/,
        use: 'html-loader',
        include: [path.resolve(__dirname, 'src/template')]
      }
    ]
  },
  resolve: {
    extensions: ['.ts', '.js']
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/' // 确保 publicPath 正确
  },
  devServer: {
    static: {
      directory: path.join(__dirname, 'dist')
    },
    allowedHosts: ['localhost', '127.0.0.1'],
    host: '127.0.0.1',
    liveReload: false,
    hot: true,
    open: false,
    port: 4000
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, 'public', 'index.html'),
      inject: 'body'
    }),
    new InjectScriptsPlugin({
      path: path.resolve(__dirname, 'src/template')
    })
  ]
}
